package com.zhihuichongcheng.application.ui.task.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zhihuichongcheng.application.R;
import com.zhihuichongcheng.application.base.BaseActivity;
import com.zhihuichongcheng.application.bean.task.TaskMsgBean;
import com.zhihuichongcheng.application.ui.task.adapter.holder.TaskMsgHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * TaskMsgAdapter Created by LK on 2017/1/6.
 */
public class TaskMsgAdapter extends RecyclerView.Adapter<TaskMsgHolder> {
    private List<TaskMsgBean> dataList = new ArrayList<>();
    private BaseActivity activity;

    public TaskMsgAdapter(BaseActivity activity) {
        this.activity = activity;
    }

    public void reSetData(List<TaskMsgBean> taskBeanList) {
        clear();
        setData(taskBeanList);
    }

    public void clear() {
        this.dataList.clear();
    }

    public void setData(List<TaskMsgBean> data) {
        this.dataList.addAll(data);
    }

    @Override
    public TaskMsgHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.listadapter_task_msg, parent, false);
        return new TaskMsgHolder(itemView, activity);
    }

    @Override
    public void onBindViewHolder(TaskMsgHolder holder, int position) {
        holder.loadData(dataList.get(position));
    }

    @Override
    public int getItemCount() {
        return this.dataList.size();
    }
}
